package com.wangyadong.hobby.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisShardInfo;

import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class RedisPressTest {
//    static  Jedis jedis = new Jedis("127.0.0.1", 6379);

    public static void main(String[] args) throws InterruptedException {
        JedisPool pool = new JedisPool("127.0.0.1", 6379);
//        jedis = new Jedis(new JedisShardInfo("127.0.0.1",6379));
//        jedis = new Jedis("127.0.0.1", 6379);
        IntStream.range(0, 2).forEach(i -> {
            new Thread(() -> {
                IntStream.range(0, 200000).forEach(j -> {
                    try {
                        Jedis jedis = pool.getResource();
//                        synchronized (jedis){
                        jedis.hset(Thread.currentThread().getId() + "" + i + "" + j + System.nanoTime(),
                                i + "->" + j, System.nanoTime() + "");
//                        }
                        jedis.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                });

            }).start();
        });


    }
}
